package com.aabte.permissionframeworklearn.permission.common;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Daniel
 */
@Data
@Builder
@AllArgsConstructor
public class ResponseBean {

    private Boolean ret;
    private String msg;
    private Object data;

    public ResponseBean() {
        this.ret = true;
        this.msg = "success";
    }

    public static ResponseBean success() {
        return new ResponseBean();
    }

    public static ResponseBean success(Object data, String msg) {
        return new ResponseBean(true, msg, data);
    }

    public static ResponseBean success(Object data) {
        return new ResponseBean(true, "success", data);
    }

    public static ResponseBean fail(String msg) {
        return new ResponseBean(false, msg, null);
    }

    public Map<String, Object> toMap() {
        Map<String, Object> result = new HashMap<>(3);
        result.put("ret", ret);
        result.put("msg", msg);
        result.put("data", data);
        return result;
    }
}
